//Sun 20 Dec 2009 01:45:24 AM CST 
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class DNAString
{
public:
	int minChanges(int maxPeriod, vector <string> dna)
	{
		string str = "";
		for(int i=0; i<dna.size(); i++)
			str += dna[i];
		int ret = str.size();
		for(int i=1; i<=maxPeriod; i++)	//The length;
		{
			int cost = 0;
			for(int j=0; j<i; j++)	//The position in each string of length i;
			{
				vector<int> sum(4,0);
				for(int k=j; k<str.size(); k+=i)	//Every kth character in each string;
				{
					if(str[k]=='A') sum[0]++;
					if(str[k]=='C') sum[1]++;
					if(str[k]=='T') sum[2]++;
					if(str[k]=='G') sum[3]++;
				}
				int mmax = max(max(sum[0], sum[1]), max(sum[2], sum[3]));
				cost += sum[0] + sum[1] + sum[2] + sum[3] - mmax;
			}
			ret = min(ret, cost);
		}
		return ret;
	}
};
